//
// Created by dxyinme on 2021/10/6.
//
#include "v_sort_array.h"
#include "v_sort_test_comm.h"
#include <random>

class VsortArrayTest : public VsortTestComm {
  void SetUp() override {
    VsortTestComm::SetUp();
  }

  void TearDown() override {
    VsortTestComm::TearDown();
  }
};

TEST_F(VsortArrayTest, testVsort120w) {
  int len = 1200000;
  int* a = new int[len];
  for (int i = 0; i < len; i ++) {
    a[i] = i;
  }
  std::shuffle(a, a + len, std::mt19937(std::random_device()()));
  Vsort::SortArrayExThread(a, len, VsortTestComm::GetThreadPoolInstance(), std::less<>());
  for (int i = 0; i + 1 < len; i ++) {
    EXPECT_LT(a[i],a[i+1]);
  }
}

TEST_F(VsortArrayTest, testVsort1200w) {
  int len = 12000000;
  int* a = new int[len];
  for (int i = 0; i < len; i ++) {
    a[i] = i;
  }
  std::shuffle(a, a + len, std::mt19937(std::random_device()()));
  Vsort::SortArrayExThread(a, len, VsortTestComm::GetThreadPoolInstance(), std::less<>());
  for (int i = 0; i + 1 < len; i ++) {
    EXPECT_LT(a[i],a[i+1]);
  }
}

TEST_F(VsortArrayTest, testVsort1200wInVectorOtherCmp) {
  int len = 12000000;
  std::vector<int> a;
  for (int i = 0; i < len; i ++) {
    a.push_back(i);
  }
  auto cmp = [](int a, int b) {
    return a > b;
  };
  std::shuffle(a.begin(), a.end(), std::mt19937(std::random_device()()));
  Vsort::SortArrayExThread(a.data(), len, VsortTestComm::GetThreadPoolInstance(), cmp);
  for (int i = 0; i + 1 < len; i ++) {
    EXPECT_GE(a[i], a[i+1]);
  }
}